<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>跟随鼠标的天使</title>
    <style>
        #mouse {
            position: absolute;
        }
    </style>
</head>

<body>
    <h1>跟随鼠标的angel</h1>
    <p>跟随鼠标移动 事件:mousemove
        <br>在页面中不断移动给docment注册事件
        <br>要图片移动不占用位置用绝对定位
        <br>核心原理:每次鼠标移动都会获得新的坐标,把这个 XY坐标作为图片的top和left值
    </p>
    <img id="mouse" src="./angel.gif" alt="">
</body>
<script>
    let m = document.querySelector('#mouse');
    document.addEventListener('mousemove', function(e) {
        //只要移动1px都会触发这个事件
        // console.log(1);
        let x = e.pageX + 'px';
        let y = e.pageY + 'px';
        console.log(`X:${x},Y:${y}`);
        m.style.left = x;
        m.style.top = y;
    })
</script>

</html>